package com.rd.student.ruanjian.class4.wangxingkai.TestOn_7_10;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

public class Test1 {
    public static void main(String[] args) {
        LinkedList list=new LinkedList();
        Students student1=new Students("王星凯",4,"ruanjian",21);
        Students student2=new Students("张睿",4,"ruanjian",14);
        Students student3=new Students("高艺铭",4,"ruanjian",53);
        Students student4=new Students("杜航",5,"ruanjian",31);
        Students student5=new Students("周子贺",4,"ruanjian",12);
        Students student6=new Students("柏云耀",4,"ruanjian",22);
        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student4);
        list.add(student5);
        list.add(student6);
        for (int i = 0; i < list.size() ; i++) {
            System.out.println(list.get(i));
        }
        System.out.println("__________");
        Collections.sort(list);
        System.out.println(list);
    }
static class Students implements Comparable{
        private String name;
        private int classNum;
        private String major;
        private int age;
        public Students() {
        }
    public Students(String name, int classNum, String major,int age) {
        this.name = name;
        this.classNum = classNum;
        this.major = major;
        this.age=age;
    }
    @Override
    public String toString() {
        return "Students{" +
                "姓名：'" + name + '\'' +
                ", 班级：" + classNum +
                ", 专业：'" + major + '\'' +", 年龄："+age+
                '}';
    }
    @Override
    public int compareTo(Object o) {
        Students s1=(Students)o;
        if (this.age> s1.age) {
            return 1;
        }else if (this.age<s1.age){
            return -1;
        }return 0;
    }
}
}

